package com.kdtech.analyse.Bbs;
import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.DoMainUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
/**
 * 橡树摄影俱乐部
 */
public class XiangshuBbsAnalyse implements AnalyseNews{

	
	public boolean isDetailPage(String url){
		boolean bRet = false;
		String[] regex = {
				"http://www.xiangshu.com/read.php\\?tid=[0-9]*",
				"http://www.xiangshu.com/read/[0-9]*/[0-9]*.html"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta bbs = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();
		bbs.setUrl(url);
		String title = null;
		String content = null;
		String author = null;
		Long date = null;
		Integer clickNum=0;
		Integer commentNum=0;

		Document doc = Jsoup.parse(htmltxt);
		title =doc.select("body > table").eq(3).select("> tbody > tr:eq(0) > td:eq(0)").text();
		date = DateUtils.matchDate(doc.select("body > table").eq(4).select("> tbody > tr > td:eq(1) > table > tbody > tr:eq(3) > td td:eq(0)").text());
		doc.select("body > table").eq(4).select("> tbody > tr > td:eq(1) a:eq(0)").remove();
		doc.select("body > table").eq(4).select("> tbody > tr > td:eq(1) div:eq(0)").remove();
		content = HtmlCleaner.getContentHtml(url,doc.select("body > table").eq(4).select("> tbody > tr > td:eq(1)"));
		if(doc.select("font[face=Gulim]").size()>0)
		{
			author = doc.select("font[face=Gulim]").get(0).text();
		}
		if(StringUtils.isBlank(title)){
		}
		bbs.setClickNum(clickNum);
		bbs.setCommentNum(commentNum);
		bbs.setTitle(StringUtils.trimSpace(title));
		bbs.setContent(content);
		bbs.setAuthor(author);
		bbs.setDate(date);
		bbs.setUpdateUrl(url);
		return bbs;
	}
	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}
    
	
}
